class Solution {
public:
    vector<vector<int>> ret;
    vector<int> path;
    bool check[9]={0};
    vector<vector<int>> permuteUnique(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        dfs(nums,0);
        return ret;
    }
    void dfs(vector<int>&nums,int t)
    {
        if(t==nums.size()) 
        {
            ret.push_back(path);
            return;
        }
        for(int i=0;i<nums.size();i++)
        {
            //这里i!=0 因为我们如果check[0]=false的时候此时从次往下的层i一定不为0
            if(check[i]==true||(i!=0&&nums[i-1]==nums[i]&&check[i-1]==false))
            {
                continue;
            }
            path.push_back(nums[i]);
            check[i]=true;
            dfs(nums,t+1);
            check[i]=false;
            path.pop_back();
        }
    }
};